Guard %ENV access with exists() checks and some minor edge case bugs I found while doing so #908
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Perl/perl5#20928 I discovered that if %ENV is locked while testing and a test fails then Test::More blows up horribly. You can argue this issue several ways, including that it is a Hash::Util testing bug. But I think Test::More can harden itself pretty reasonably against this issue by simply checking for key existence before reading a key. I did not attempt to deal with the places where there are writes to ENV, obviously that is going to end badly if %ENV is locked. But reading from a locked %ENV during testing is easy to guard against and obviously at least possible to happen since code doing so has been in perl core for a long time. :-)
Related tickets:
#907
Perl/perl5#20929
Along the way I noticed a subtle error in the logic for parsing the T2_FORMATTER env var. If the string is set to "+" it would end up setting the formatter to the empty string. I also realized it was possible for the logic to not set it at all, and step past the defaulting logic in Test2::API::Instance. So I fixed it. Since part of this logic reads from the %ENV I dealt with both issues in the same commit. Hope that is ok.